{extend name="homeheader:header"/}
{block name="content"}
	<link rel="stylesheet" type="text/css" href="/home/css/of_order.css" />
	<body style="overflow-x: hidden;">
		<div class="of_order">
			<div class="top">
				<a href="javascript:history.back(-1)" class="back">
					<i class="iconfont">&#xe615;</i></a>
				确认订单
			</div>
			<div class="sh row" id="useraddress">
				<div class="col-xs-1">
					<i class="iconfont icon-dizhi"></i>
				</div>
				<div class="col-xs-11">
					<input type="hidden" name="" value="{$address.id}" id="addressid" />
					<input type="hidden" name="" value="{$ids}" id="ids" />
					<input type="hidden" name="" value="{$gids}" id="gids" />
					<i class="iconfont">&#xe608;</i><p class="row"><span>收货人：</span><span>{$address.a_name}</span><span>{$address.a_tel}</span></p>
					<div class="">
						收货地址：{$address.a_address}
					</div>
					<span>(请确认正确的收货地址)</span>
				</div>
			</div>
			<div class="wrap_bt">
				<ul>
					{foreach name="list" item="vo"}
					<li>
						<input type="hidden" value="{$vo.gid}" id="goodsid{$vo.gid}" class="goodsid" />
						<div class="b_top container row">
							<div class="le col-xs-3">
								<img src="{$vo.g_pic.url}" />
							</div>
							<div class="col-xs-9">
								<h3>{$vo.g_name}</h3>
								<small>{$vo.g_description}</small>
							</div>
						</div>
						<div class="b_se">
							<p>购买数量</p>
							<ul class="name row">
								<li>规格</li>
								<li>单价</li>
								<li>购买数量</li>
								<li>总价</li>
							</ul>
							<ul class="init row">
								{foreach name="vo['info']" item="v1"}
									<input type="hidden" value="{$v1.iid}" id="goodstype{$v1.iid}">
									<li>{$v1.i_name}</li>
									<li>￥{$v1.i_price}</li>
									<li>{$v1.ci_number}</li>
									<li>￥{$v1.ci_total}</li>
								{/foreach}
							</ul>
						</div>
					</li>
					{/foreach}
				</ul>
				<div class="mone">
					<p>所有商品总价： <span>￥{$total}</span></p>
				</div>
				<input type="hidden" value="{$user.u_wallet}" id="u_wallet" />
				<div class="fx_b">
					<div class="msg">
					<span>买家留言：</span>
					<input type="text" name="message" id="message" value="" placeholder="填写需求" />
				</div>
				<div class="clk row">
					<div class="site-demo-button" id="clk" style="margin-bottom: 0;">
						<a data-method="offset" data-type="b" class="layui-btn layui-btn-normal bt">提交订单</a>
						<div>
							总价：<span>￥{$total}</span>
						</div>
					</div>

				</div>
				</div>
			</div>
		</div>
	</body>
	<div class="ap_of" style="display: none;">
		<h3>￥<span id="o_tprice">{$total}</span></h3>
		<p>付款方式</p>
		<form class="layui-form" action="" lay-filter="example">
			<ul>
				<li>
					<div class="layui-input-block">
						<input type="radio" name="money" class="money" title="余额" value="1" />
					</div>
				</li>
				<li>
					<div class="layui-input-block">
						<input type="radio" name="money" class="money" title="微信" value="2" />
					</div>
				</li>
				<li>
					<div class="layui-input-block">
						<input type="radio" name="money" class="money" title="支付宝" value="3" />
					</div>
				</li>
		</ul>
		</form>
	</div>
	<script type="text/javascript">
		layui.use('layer', function() { //独立版的layer无需执行这一句
			var $ = layui.jquery,
				layer = layui.layer; //独立版的layer无需执行这一句

			//触发事件
			var active = {
				offset: function(othis) {
					var type = othis.data('type'),
						text = othis.text();
					layer.open({
						type: 1
						,offset: type
						,id: 'clk' + type //防止重复弹出
						,content: $(".ap_of")
						,btn: '立即付款'
						,btnAlign: 'c' //按钮居中
						,shade: .7 //不显示遮罩
						,anim:6
						,area: ['100%', ''],
						closeBtn:1,
						title: ['确认付款', 'text-align: center;'],
						yes: function() {
							var o_type = '';
					  	  	$("input[type='radio'][class='money']:checked").each(function(){ 
					  	  		o_type = $(this).val();
					  	  	});

					  	  	/* 订单总金额 */
					  	  	var o_tprice = Number($('#o_tprice').text());

					  	  	/* 收货id */
							var aid = $('#addressid').val();

							/* 客户留言 */
							var o_message = $('#message').val();

							/*  用户的余额 */
							var u_wallet = Number($('#u_wallet').val());

							var gids = $('#gids').val();
							/* 未付款 */
							if(o_type == ''){
								$.post('/home/orders/addOrders',{o_tprice:o_tprice,aid:aid,o_message:o_message,o_type:o_type,gids:gids},function(res){
									var oid = Number(res.data);
									/* 购物车选中的购物车id */
									var ids = $('#ids').val();
									$.post('/home/orders/addOrdersInfo',{oid:oid,ids:ids},function(re){

										if(re.code == 0){
											layer.msg(res.msg,{icon:6});
											setTimeout(function(){
						                    	window.location.href="/home/orders/norder/?id="+oid;
						                	},1000);
										}
										
									});
								},'json');
									
							}else if(o_type == '1'){
								/* 余额不足 */
								if(u_wallet<o_tprice){
									var otype = null;
									layer.msg('账户余额不足', {icon: 5});
									$.post('/home/orders/addOrders',{o_tprice:o_tprice,aid:aid,o_message:o_message,o_type:otype,gids:gids},function(res){
										var oid = Number(res.data);
										/* 购物车选中的购物车id */
										var ids = $('#ids').val();
										$.post('/home/orders/addOrdersInfo',{oid:oid,ids:ids},function(re){

											if(re.code == 0){
												layer.msg(res.msg,{icon:6});
												setTimeout(function(){
							                    	window.location.href="/home/orders/norder/?id="+oid;
							                   	},1000);
											}
										});
									},'json');
								}else{
									/* 余额付款 */
									$.post('/home/orders/addOrders',{o_tprice:o_tprice,aid:aid,o_message:o_message,o_type:o_type,gids:gids},function(res){
										var oid = Number(res.data);
										/* 购物车选中的购物车id */
										var ids = $('#ids').val();
										$.post('/home/orders/addOrdersInfo',{oid:oid,ids:ids},function(re){
											if(re.code == 0){
												layer.msg('使用余额付款成功',{icon:6});
												setTimeout(function(){
							                    	window.location.href="/home/orders/osuccess/?id="+oid;
							                    },1000);
											}
										},'json');
									},'json');
								}

							}else if(o_type == '2'){
								/* 微信付款 */
								layer.msg('还没有做', {icon: 5});
								
							}else if(o_type == '3'){
								/* 支付宝付款 */
								$.post('/home/orders/addOrders',{o_tprice:o_tprice,aid:aid,o_message:o_message,o_type:o_type,gids:gids},function(res){
									var oid = Number(res.data);
									/* 购物车选中的购物车id */
									var ids = $('#ids').val();
									$.post('/home/orders/addOrdersInfo',{oid:oid,ids:ids},function(re){
										$.post('/home/Pay/pay_order',{id:oid,o_type:o_type},function(r){
											console.log(r);
										},'json');
									},'json');
								},'json');  
								
							}
						
						}
					});
				}
			};

			$('#clk .layui-btn').on('click', function() {
				var othis = $(this),
					method = othis.data('method');
				active[method] ? active[method].call(this, othis) : '';
			});

		});
		layui.use(['form', 'layedit', 'laydate'], function() {
			var form = layui.form,
				layer = layui.layer,
				layedit = layui.layedit,
				laydate = layui.laydate;
		});

		$('#useraddress').click(function(){
			window.location.href="/home/user/address";
		});

	</script>

</html>
{/block}